#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<dirent.h>

int main(int argc, char *argv[]){

    
    if(argc != 2){
        
        printf("参数错误!\n");
        return -1;
    }    

    int fd = open(argv[1], O_RDONLY|O_DIRECTORY);
    if(fd < 0){
        
        perror("文件夹打开失败");
        return -1;
    }else{

        printf("%d\n", fd);
    }
   DIR *dir =  fdopendir(fd);
   if(dir == NULL){
    
       perror("文件夹指针转换失败");
   }

   struct dirent *dirent = NULL;
   while((dirent = readdir(dir))!= NULL){
    
        printf("%s\n",dirent->d_name);
   }

   close(fd);
   return 0;
}
